<?php
namespace test\primary;
include 'sql_action.php';
$acc = $_POST['username'];
$pwd = $_POST['pwd'];

if ($_POST['username'] == '' || $_POST['pwd'] == '') {
    $win = 1;
};

$conn = new \mysqli();
$conn->connect('127.0.0.1', 'root', '123456', 'userinfo');
if (!empty($conn->connect_error)) {
    $win = 2;
}
sql_action::set_conn($conn);
$sql = 'insert into user_info (Account,pwd)values (\'' . $acc . '\',\'' . $pwd . '\')';
$result = sql_action::add($sql);
if ($result) {
    $win = 0;
} else {
    $win = 3;
}
?>
<!DOCTYPE html>
<html>
<body>

</body>
<script>
    switch (<?php echo $win ?>) {
        case 1 :
            alert('你没有完整地输入账号和密码');
            window.location.href = 'create_acc.php';
            break;
        case 2 :
            alert('数据库连接失败，请联系管理员');
            window.location.href = 'create_acc.php';
            break;
        case 3 :
            alert('该账号已被创建');
            window.location.href = 'create_acc.php';
            break;
        case 0 :
            alert('账号创建成功->即将前往登录');
            window.location.href = '../login.php';
            break;
    }
</script>
</html>
